<template>
    <div class="pagination">
    <!-- 上 -->
    <button :disabled="pageNo===1" @click="$emit('goPageNo',pageNo-1)">
      上一页
    </button>
    <button
      v-if="pageStart > 1"
      :class="{ active: pageNo == 1 }"
      @click="$emit('goPageNo',1)"
    >
      1
    </button>
    <button v-if="pageStart> 2">···</button>
    <!-- 中间部分 -->
    <button
      v-show="page>=pageStart"
      v-for="(page, index) in pageEnd"
      :key="index"
      :class="{ active: pageNo == page }"
      @click="$emit('goPageNo',page)"
    >
      {{ page }}
    </button>
    <!-- 下 -->
    <button v-if="pageEnd < totalPage - 1">···</button>
    <button
      v-if="pageEnd< totalPage"
      @click="$emit('goPageNo',totalPage)"
      :class="{active:pageNo==totalPage}"
    >
      {{ totalPage }}
    </button>
    <button
      :disabled="pageNo===totalPage"
      @click="$emit('goPageNo',pageNo+1)"
    >
      下一页
    </button>

    <button style="margin-left: 30px">共 {{ totalPage }} 条</button>
    </div>
</template>
<script>
export default {
    data(){
        return{
            pageStart:0,
            pageEnd:0,
        }
    },
    watch:{
        pageNo:{
          handler:function(){
                const nubmer=Math.floor(this.pageNumber/2)  //联系页面减加多少
                this.pageStart= this.pageNo-nubmer //连续页码开始值
                console.log('促发',this.pageStart)
                this.pageEnd= this.pageNo+nubmer//连续页码最后的值
                if( this.pageStart<=1){
                    this.pageStart=1
                    this.pageEnd=this.pageNumber    
                }
                if(this.pageEnd>=this.totalPage){
                    console.log('jinr')
                    this.pageEnd=this.totalPage
                    this.pageStart=this.totalPage-5+1 
                }
                console.log(this.pageStart,this.pageNo,this.pageEnd)
          },
         immediate:true
          
        }
    },
    methods:{
    },
    props:['pageNo','pageSize','totalNubmer','pageNumber'],
    computed:{
        totalPage(){
            return Math.ceil(this.totalNubmer/this.pageSize) 
        }
    }
}
</script>
<style lang="less" scoped>
.pagination {
  text-align: center;
  button {
    margin: 0 5px;
    background-color: #f4f4f5;
    color: #606266;
    outline: none;
    border-radius: 2px;
    padding: 0 4px;
    vertical-align: top;
    display: inline-block;
    font-size: 13px;
    min-width: 35.5px;
    height: 28px;
    line-height: 28px;
    cursor: pointer;
    box-sizing: border-box;
    text-align: center;
    border: 0;

    &[disabled] {
      color: #c0c4cc;
      cursor: not-allowed;
    }

    &.active {
      cursor: not-allowed;
      background-color: #409eff;
      color: #fff;
    }
  }
}
.active{
  background: skyblue;
}
</style>
